<template>
  <div class="app-container">
    <!--
      data   用来展示数据
      props  树状图配置
      label    指定节点标签为节点对象的某个属性值
      children 指定子树为节点对象的某个属性值
      disabled 指定节点选择框是否禁用为节点对象的某个属性值
      isLeaf     指定节点是否为叶子节点，仅在指定了 lazy 属性的情况下生效  (就是设置这个节点是否有右箭头，懒加载模式下才有)
      @node-click 节点的点击事件
    -->

    <el-row :gutter="20">
      <el-col :span="10" :xs="24">
        <el-card class="category-tree" style="margin-bottom:20px;">
          <div slot="header" class="clearfix">
            <span>分类管理</span>
          </div>
          <div class="tree-content">
            <el-input
              v-model="filterTreeText"
              placeholder="输入关键字"
              style="margin-bottom: 10px;"
            />
            <div class="tree-btn-content">
              <el-button icon="el-icon-circle-plus" @click="treeOpen"
                >展开</el-button
              >
              <el-button icon="el-icon-remove" @click="treeClose"
                >收起</el-button
              >
            </div>
            <el-tree
              v-if="!refresh"
              ref="tree"
              highlight-current
              draggable
              :data="treeData"
              :props="defaultProps"
              :load="loadNode"
              :default-expanded-keys="['-1']"
              current-node-key="-1"
              :expand-on-click-node="false"
              node-key="ID"
              lazy
              :allow-drop="allowDrop"
              :allow-drag="allowDrag"
              :filter-node-method="filterNode"
              @node-click="handleNodeClick"
            />
          </div>
        </el-card>
      </el-col>
      <el-col class="category-form" :span="14" :xs="24">
        <el-card
          v-loading="detailLoading"
          class="category-body-form"
          :class="isFixedForm ? 'form-fixed' : ''"
          element-loading-text="拼命加载中"
          style="margin-bottom:20px;"
        >
          <div slot="header" class="clearfix">
            <span>分类详情</span>
          </div>
          <el-form
            ref="dataForm"
            :rules="rules"
            :model="temp"
            label-position="right"
            label-width="80px"
            style="margin-left:20px;"
          >
            <el-form-item label="父项" prop="parentID">
              <el-select
                v-model="temp.parentID"
                class="filter-item"
                clearable
                placeholder="请选择父项"
                style="width: 80%;"
                disabled
              >
                <el-option
                  v-for="item in this.categoryList"
                  :key="item.ID"
                  :label="item.name"
                  :value="item.ID"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="名称" prop="name">
              <el-input
                v-model="temp.name"
                placeholder="名称"
                style="width: 80%;"
                :disabled="formDisabled"
              />
            </el-form-item>
            <!--            <el-form-item label="仪器类型" prop="instrumentType">-->
            <!--              <el-select-->
            <!--                v-model="temp.instrumentType"-->
            <!--                class="filter-item"-->
            <!--                ref="instrumentType"-->
            <!--                clearable-->
            <!--                placeholder="请选择仪器类型"-->
            <!--                style="width: 90%;"-->
            <!--              >-->
            <!--                <el-option v-for="item in this.instrumentTypes" :key="item.key" :label="item.display_name" :value="item.key" />-->
            <!--              </el-select>-->
            <!--            </el-form-item>-->
            <el-form-item label="简称" prop="shortName">
              <el-input
                v-model="temp.shortName"
                placeholder="简称"
                style="width: 80%;"
                :disabled="formDisabled"
              />
            </el-form-item>
            <el-form-item label="编码" prop="code">
              <el-input
                v-model="temp.code"
                placeholder="编码"
                style="width: 80%;"
                :disabled="formDisabled"
              />
            </el-form-item>
            <el-form-item label="描述" prop="description">
              <el-input
                v-model="temp.description"
                type="textarea"
                placeholder="描述"
                :autosize="{ minRows: 8, maxRows: 15 }"
                style="width: 80%;"
                :disabled="formDisabled"
              />
            </el-form-item>
            <!--          <el-form-item label="列表图" prop="listImage">-->
            <!--            <el-input v-model="temp.listImage" placeholder="列表图" style="width: 80%;"/>-->
            <!--          </el-form-item>-->
            <!--          <el-form-item label="压题图" prop="faceImage">-->
            <!--            <el-input v-model="temp.faceImage" placeholder="压题图" style="width: 80%;"/>-->
            <!--          </el-form-item>-->
            <el-form-item label="排序号" prop="orderSeq">
              <el-input
                v-model="temp.orderSeq"
                placeholder="排序号"
                type="number"
                style="width: 80%;"
                disabled
              />
            </el-form-item>
            <el-form-item label="层级" prop="levelSeq">
              <el-input
                v-model="temp.levelSeq"
                placeholder="层级"
                type="number"
                style="width: 80%;"
                disabled
              />
            </el-form-item>
            <!--            <el-form-item label="参数1" prop="parameter1">-->
            <!--              <el-input v-model="temp.parameter1" placeholder="参数1" style="width: 80%;"/>-->
            <!--            </el-form-item>-->
            <!--            <el-form-item label="参数2" prop="parameter2">-->
            <!--              <el-input v-model="temp.parameter2" placeholder="参数2" style="width: 80%;"/>-->
            <!--            </el-form-item>-->
            <!--            <el-form-item label="参数3" prop="parameter3">-->
            <!--              <el-input v-model="temp.parameter3" placeholder="参数3" style="width: 80%;"/>-->
            <!--            </el-form-item>-->
            <el-form-item
              v-if="appID == '000000000000000000000000000000000000'"
              label="对象定义"
              prop="objectDefineID"
            >
              <el-select
                v-model="temp.objectDefineID"
                class="filter-item"
                clearable
                placeholder="请选择对象定义"
                style="width: 80%;"
                :disabled="formDisabled"
              >
                <el-option
                  v-for="item in this.objectDefineList"
                  :key="item.ID"
                  :label="item.name"
                  :value="item.ID"
                />
              </el-select>
            </el-form-item>
          </el-form>
          <div style="text-align: center">
            <!--          增加子节点-->
            <el-button
              v-if="
                buttonStatus === '' ||
                  buttonStatus === 'back' ||
                  buttonStatus === 'click'&& !root
              "
              type="success"
              @click="handleCreate"
            >
              增加子节点
            </el-button>

            <!--          修改-->
            <el-button
              v-if="buttonStatus === 'click' && !root"
              type="warning"
              @click="handleUpdate"
            >
              编辑
            </el-button>

            <!--          删除-->
            <el-button
              v-if="buttonStatus === 'click' && !root"
              type="danger"
              @click="handleDelete"
            >
              删除
            </el-button>

            <!--          另存为-->
            <el-button
              v-if="buttonStatus === 'update'"
              type="primary"
              @click="saveAs"
            >
              另存为
            </el-button>

            <!--          编辑创建-->
            <el-button
              v-if="buttonStatus === 'update' || buttonStatus === 'create'"
              type="success"
              @click="buttonStatus === 'create' ? createData() : updateData()"
            >
              {{ textMap[buttonStatus] }}
            </el-button>

            <!--          取消-->
            <el-button
              v-if="buttonStatus === 'update' || buttonStatus === 'create'"
              @click="
                ;(buttonStatus = 'click'),
                  (formDisabled = true),
                  (temp = selectNodeData)
              "
            >
              取消
            </el-button>

            <!--          锁定解锁-->
            <!--          <el-button v-if="buttonStatus === 'update' && temp.isLock ===0" size="mini" type="warning" @click="handleModifyLock('1')">-->
            <!--            锁定-->
            <!--          </el-button>-->
            <!--          <el-button v-if="buttonStatus === 'update' && temp.isLock ===1" size="mini" type="info" @click="handleModifyLock('0')">-->
            <!--            取消锁定-->
            <!--          </el-button>-->
          </div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import {
  createCategory,
  deleteCategory,
  fetchCategoryOne,
  updateCategory,
  lockCategory,
  unlockCategory,
  moveOneCategory
} from '@/api/system/category'
import { getToken,getItem } from '@/plugins/auth'
import { isNotEmpty, zEnBase64, debounce } from '@/plugins'
import { getCategoryList } from '@/api/base'
import global from '@/common'
import option from '@/common/weixing/option'
const instrumentTypes = option.instrumentTypes
const instrumentTypesValue = instrumentTypes.reduce((acc, cur) => {
  acc[cur.key] = cur.display_name
  return acc
}, {})

export default {
  name: 'Category',
  filters: {
    instrumentTypeFilter(instrumentType) {
      return instrumentTypesValue[instrumentType]
    }
  },
  data() {
    return {
      filterTreeText: '', // 搜索树关键词
      isFixedForm: false, // 表彰固定定位
      detailLoading: false, // 详情loading状态
      selectNodeData: null, // 选中的节点详情数据
      selectNode: null, // 选中树节点对象
      formDisabled: true, // 表单是禁用
      appID: global.roleID,
      listLoading: true,
      root: false,
      refresh: false,
      isSuperAdmin: global.roleID === '000000000000000000000000000000000000',
      temp: {
        ID: '',
        parentID: '',
        name: '',
        shortName: '',
        code: '',
        description: '',
        listImage: '',
        faceImage: '',
        instrumentTypes: '',
        orderSeq: '',
        levelSeq: '',
        parameter1: '',
        parameter2: '',
        parameter3: '',
        objectDefineID: '',
        isLock: ''
      },
      buttonStatus: '',
      textMap: {
        create: '保存',
        update: '保存',
        back: '返回'
      },
      rules: {
        name: [{ required: true, message: '名称不能为空', trigger: 'blur' }]
        // code: [{ required: true, message: '编码不能为空', trigger: 'blur' }]
      },
      listQuery: {
        token: getToken(),
        resultArray:
          'ID,' +
          'application.applicationID.name,' +
          'organization.organizationID.name,' +
          'name,shortName,instrumentType,orderSeq,parentID',
        keyWordArray: 'name,shortName',
        parameterArray: 'parentID=-1',
        orderArray: 'orderSeq=1',
        pageNumber: 10000
      },
      treeData: [
        {
          ID: '-1',
          name: '根'
        }
      ],
      categoryList: [],
      objectDefineList: [],
      childTreeData: [],
      detailTreeDate: [],
      instrumentTypes,
      clickID: '',
      node_had: [], // 这里是关键！在data里面定义一个变量，将node.level == 0的node存起来
      resolve_had: [], // 同上，把node.level == 0的resolve也存起来
      defaultProps: {
        id: 'ID',
        label: 'name'
      }
    }
  },
  watch: {
    filterTreeText(val) {
      this.$refs.tree.filter(val)
    }
  },
  created() {
    this.getList()
  },
  mounted() {
    this.scrollFixed = debounce(this.scrollFixed, 100)
    window.addEventListener('scroll', this.scrollFixed)
  },
  beforeDestroy() {
    window.removeEventListener('scroll', this.scrollFixed)
  },
  methods: {
    getList() {
      // this.refresh = true
      // this.listLoading = true
      // this.categoryList = []
      // let url = `https://kpinterface.shejidedao.cn/interface-server/api/outSystemGetCategoryList?outToken=${getToken()}`;
      // this.axios(url).then((response) => {
      //     this.categoryList = response.body.data.rows
      //     this.refresh = false
      // });
      // getCategoryList(null, 'parentID').then(response => {
      //   this.categoryList = response.body.data.rows
      //   this.refresh = false
      // })
    },
    getCategoryxxx() {},
    handleModifyLock(isLock) {
      const params = {
        token: getToken(),
        parameterArray: 'ID=' + this.temp.ID
      }
      if (isLock === '1') {
        // 锁定
        lockCategory(params).then(response => {
          this.getList()
          this.$message({
            message: response.header.msg,
            type: response.header.code === 0 ? 'success' : 'error'
          })
        })
      } else if (isLock === '0') {
        // 取消锁定
        unlockCategory(params).then(response => {
          this.getList()
          this.$message({
            message: response.header.msg,
            type: response.header.code === 0 ? 'success' : 'error'
          })
        })
      }
    },
    resetTemp() {
      this.temp = {
        ID: '',
        parentID: '',
        name: '',
        shortName: '',
        code: '',
        description: '',
        instrumentType: '',
        listImage: '',
        faceImage: '',
        orderSeq: '',
        levelSeq: '',
        parameter1: '',
        parameter2: '',
        parameter3: '',
        objectDefineID: '',
        isLock: ''
      }
    },
    handleCreate() {
      this.formDisabled = false
      this.resetTemp()
      const node = this.$refs.tree.getNode(this.$refs.tree.getCurrentNode())
      this.temp.orderSeq = node.childNodes.length + 1
      this.temp.levelSeq = node.level
      
      this.buttonStatus = 'create'
      this.$nextTick(() => {
        this.$refs['dataForm'].clearValidate()
      })
      this.temp.parentID = this.clickID
    },
    createData(refresh) {
      this.$refs['dataForm'].validate(valid => {
        if (valid) {
          let params = ''
          params += 'name=' + this.temp.name
          params +=
            '&applicationID=' +
            getItem('applicationID')
          if (isNotEmpty(this.temp.shortName)) {
            params += '&shortName=' + this.temp.shortName
          }
          if (isNotEmpty(this.temp.code)) {
            params += '&code=' + this.temp.code
          }
          if (isNotEmpty(this.temp.description)) {
            params += '&description=' + this.temp.description
          }
          params += '&orderSeq=' + (isNotEmpty(this.temp.orderSeq) ? this.temp.orderSeq : '') 
          params += '&levelSeq=' +  (isNotEmpty(this.temp.levelSeq) ? this.temp.levelSeq : '') 
          console.log(this.temp.parentID,'this.temp.parentID');
          let url = `https://kpinterface.shejidedao.cn/interface-server/api/outSystemCreateOneCategory?outToken=${getToken()}&parentID=${this.temp.parentID}&${params}`;
          this.axios(url).then((response) => {
              this.dialogFormVisible = false
              this.$notify({
                title: '成功',
                message: '创建成功',
                type: 'success',
                duration: 2000
              })
              const categoryID = response.body.categoryID
              this.refreshNode(refresh || 'current', categoryID)
              // this.temp.parentID = response.body.categoryID
              this.clickID = response.body.categoryID
          });
          this.formDisabled = true
          this.buttonStatus = 'back'
        }
      })
    },
    getCategoryDetail(ID) {
      let url = `https://kpinterface.shejidedao.cn/interface-server/api/outSystemGetOneCategoryDetail?outToken=${getToken()}&categoryID=${ID}`;
      this.axios(url).then((response) => {
          this.temp = response.body.data
          this.selectNodeData = response.body.data
          this.dialogStatus = 'update'
          this.dialogFormVisible = true
          this.detailLoading = false
          this.$nextTick(() => {
            this.$refs['dataForm'].clearValidate()
          })
      });
    },
    handleUpdate() {
      this.formDisabled = false
      this.buttonStatus = 'update'
    },
    updateData() {
      this.$refs['dataForm'].validate(valid => {
        if (valid) {
          let params = ''
          params += 'outToken=' + getToken()
          params += '&parentID=' + this.temp.parentID
          params += '&categoryID=' + this.temp.id
          params += '&name=' + (isNotEmpty(this.temp.name) ? this.temp.name : '')
          params += '&shortName=' + (isNotEmpty(this.temp.shortName) ? this.temp.shortName : '')
          params += '&code=' + (isNotEmpty(this.temp.code) ? this.temp.code : '')
          params += '&description=' + (isNotEmpty(this.temp.description) ? this.temp.description : '')
          params += '&orderSeq=' + (isNotEmpty(this.temp.orderSeq) ? this.temp.orderSeq : '') 
          params += '&levelSeq=' +  (isNotEmpty(this.temp.levelSeq) ? this.temp.levelSeq : '') 

          let url = `https://kpinterface.shejidedao.cn/interface-server/api/outSystemUpdateOneCategory?${params}`;
          this.axios(url).then((response) => {
              this.dialogFormVisible = false
              this.$notify({
                title: '成功',
                message: '更新成功',
                type: 'success',
                duration: 2000
              })
              this.refreshNode('parent')
          })
          this.buttonStatus = 'back'
          this.formDisabled = true
        }
      })
    },
    refreshNode(type, selectedId) {
      const currentNode = this.$refs.tree.getNode(
        this.$refs.tree.getCurrentKey()
      )
      const nodeId =
        type === 'current' ? currentNode.data.ID : currentNode.data.parentID
      const node = this.$refs.tree.getNode(nodeId)
      node.loaded = false
      node.expand()
      this.$nextTick(() => {
        setTimeout(() => {
          if (selectedId) {
            this.$refs.tree.setCurrentKey(selectedId)
            this.buttonStatus = 'click'
            this.detailLoading = true
            this.getCategoryDetail(selectedId)
          }
        }, 1000)
      })
    },
    filterNode(value, data) {
      if (!value) return true
      return data.name.indexOf(value) !== -1
    },
    saveAs() {
      this.createData('parent')
    },
    handleDelete() {
      this.$confirm('是否确认删除 ' + this.temp.name + '?', {
        type: 'warning',
        closeOnClickModal: false, // 点击区域外不可关闭
        closeOnPressEscape: false // 按ESC不可关闭
      }).then(() => {
        let url = `https://kpinterface.shejidedao.cn/interface-server/api/outSystemDeleteOneCategory?outToken=${getToken()}&categoryID=${this.temp.id}`;
        this.axios(url).then((response) => {
            this.$notify({
              title: '成功',
              message: '删除成功',
              type: 'success',
              duration: 2000
            })
            this.refreshNode('parent',this.temp.parentID)
        })
        this.buttonStatus = 'back'
      })
    },
    // 点击事件
    handleNodeClick(data) {
      let id = ''
      this.buttonStatus = 'click'
      this.detailLoading = true
      this.root = false
      if (data.ID === '-1') {
        this.root = true
        this.getCategoryDetail(-1)
        id = -1
      } else if (data.categoryID) {
        this.getCategoryDetail(data.categoryID)
        id = data.categoryID
      } else if (data.id) {
        this.getCategoryDetail(data.id)
        id = data.id
      }
      this.clickID = id
      // this.temp.parentID = data.ID
    },
    // 点击下级
    loadNode(node, resolve) {
      if (node.level === 0) {
        // 请求一级tree菜单
        this.node_had = node // 这里是关键！在data里面定义一个变量，将node.level == 0的node存起来
        this.resolve_had = resolve // 同上，把node.level == 0的resolve也存起来
        setTimeout(() => {
          this.$nextTick(() => {
            this.handleNodeClick(node.data[0])
          })
        }, 1000)
        return resolve(this.treeData)
      }
      if (node.level === 1 || node.level > 1) {
        // 请求二级tree菜单及其他子级节点
        this.getChildrenNode(node, resolve)
      }
    },
    // getTreeData(termSysId) {
    //   // termSysId 下拉框选择值Id
    //   let _this = this
    //   _this.$http({
    //     url: _this.$http.adornUrl(_this.apiUrl.getTopVocabularyId),
    //     method: 'post',
    //     params: _this.$http.adornParams({ 'vocabularyId': _this.form.termSys }, false)
    //   }).then(({ data }) => {
    //     if (data && data.success == true) {
    //       _this.treeData = data.data
    //       _this.detailTreeDate = []
    //       _this.node_had.childNodes = [] // 把存起来的node的子节点清空，不然会界面会出现重复树！
    //       _this.loadNode(_this.node_had, _this.resolve_had) // 再次执行懒加载的方法
    //     } else {
    //       _this.$message({
    //         showClose: true,
    //         message: data.msg,
    //         type: 'error'
    //       })
    //     }
    //   })
    // },
    getChildrenNode(node, resolve) {
      let parentID = ''
      if (node.level == 2) {
        parentID = node.data.categoryID
      } else if (node.level > 2) {
        parentID = node.data.id
      }
      if (node.level == 1) { 
        let url = `https://kpinterface.shejidedao.cn/interface-server/api/outSystemGetApplicationCategoryList?outToken=${getToken()}&applicationID=${getItem('applicationID')}`;
        this.axios(url).then((response) => {
            let data = response.body.data.rows,arr=[];
            data.forEach(v => {
              v.ID = v.id
              arr.push(v)
            })
            resolve(arr)
        });
      } else {
        let url = `https://kpinterface.shejidedao.cn/interface-server/api/outSystemGetCategoryList?outToken=${getToken()}&parentID=${parentID}`;
        this.axios(url).then((response) => {
            let data = response.body.data.rows,arr=[];
            data.forEach(v => {
              v.ID = v.id
              arr.push(v)
            })
            resolve(arr)
        });
      }
      // this.childTreeData = []
      // if (global.roleID == '000000000000000000000000000000000000') {
      //   getCategoryList('parentID=' + node.data.ID, 'parentID').then(
      //     response => {
      //       // const result = response.body.data.rows

      //       // this.childTreeData = response.body.data.rows
      //       resolve(response.body.data.rows)
      //     }
      //   )
      // } else {
      //   getCategoryList(
      //     'parentID=' +
      //       node.data.ID +
      //       ',applicationID=' +
      //       this.$store.state.user.info.applicationID +
      //       ',organizationID=' +
      //       this.$store.state.user.info.organizationID,
      //     'parentID'
      //   ).then(response => {
      //     // const result = response.body.data.rows
      //     // console.warn(result)
      //     // this.childTreeData = response.body.data.rows
      //     resolve(response.body.data.rows)
      //   })
      // }
    },
    nodeDrop(draggingNode, dropNode, dropType) {
      if (!draggingNode.data) {
        return false
      }
      let moveSide = ''
      if (dropType === 'before') {
        moveSide = '1'
      } else if (dropType === 'after') {
        moveSide = '2'
      }
      const params = {
        token: getToken(),
        moveCategoryID: draggingNode.data.ID,
        categoryID: dropNode.data.ID,
        moveSide
      }
      moveOneCategory(
        params.moveCategoryID,
        params.categoryID,
        params.moveSide,
        params.token
      )
        .then(res => {
          if (res.header.code === 0) {
            this.$message({
              message: '移动成功',
              type: 'success'
            })
          }
        })
        .catch(_ => {
          this.$message({
            message: '移动失败',
            type: 'error'
          })
        })
      // Promise.all([
      //   fetchCategoryOne(params),
      //   fetchCategoryOne(dropNodeParams)
      // ]).then(res => {
      //   const draggingData = res[0].body.data
      //   const dropData = res[1].body.data
      //   if (dropType === 'before') {
      //     draggingData.orderSeq = dropData.orderSeq - 1
      //   } else if (dropType === 'after') {
      //     draggingData.orderSeq = dropData.orderSeq + 1
      //   }
      //   this.dragUpdate(draggingData)
      // }).catch(() => {})
    },
    dragUpdate(temp) {
      let params = ''
      params += 'ID=' + temp.ID
      params +=
        ',parentID=' +
        (isNotEmpty(temp.parentID) ? zEnBase64(temp.parentID) : '')
      params += ',name=' + (isNotEmpty(temp.name) ? zEnBase64(temp.name) : '')
      params +=
        ',shortName=' +
        (isNotEmpty(temp.shortName) ? zEnBase64(temp.shortName) : '')
      params += ',code=' + (isNotEmpty(temp.code) ? zEnBase64(temp.code) : '')
      params +=
        ',description=' +
        (isNotEmpty(temp.description) ? zEnBase64(temp.description) : '')
      params +=
        ',listImage=' +
        (isNotEmpty(temp.listImage) ? zEnBase64(temp.listImage) : '')
      // params +=
      //   ',instrumentType=' +
      //   (isNotEmpty(this.temp.instrumentType)
      //     ? zEnBase64(this.temp.instrumentType)
      //     : '')
      params +=
        ',faceImage=' +
        (isNotEmpty(temp.faceImage) ? zEnBase64(temp.faceImage) : '')
      params +=
        ',orderSeq=' +
        (isNotEmpty(temp.orderSeq) ? zEnBase64(temp.orderSeq) : '')

      params +=
        ',levelSeq=' +
        (isNotEmpty(temp.levelSeq) ? zEnBase64(temp.levelSeq) : '')

      params +=
        ',parameter1=' +
        (isNotEmpty(temp.parameter1) ? zEnBase64(temp.parameter1) : '')
      params +=
        ',parameter2=' +
        (isNotEmpty(temp.parameter2) ? zEnBase64(temp.parameter2) : '')
      params +=
        ',parameter3=' +
        (isNotEmpty(temp.parameter3) ? zEnBase64(temp.parameter3) : '')
      params +=
        ',objectDefineID=' +
        (isNotEmpty(temp.objectDefineID) ? zEnBase64(temp.objectDefineID) : '')
      const data = {
        token: getToken(),
        parameterArray: params
      }
      updateCategory(data)
    },
    allowDrop(draggingNode, dropNode, type) {
      // if (type === 'inner') {
      //   return false
      // } else {
      //   return true
      // }
      // eslint-disable-next-line no-empty
      if (
        draggingNode.data.parentID &&
        draggingNode.data.parentID === dropNode.data.parentID
      ) {
      } else {
        return false
      }
      if (draggingNode.level === dropNode.level && type !== 'inner') {
        return true
      } else {
        return false
      }
    },
    allowDrag(draggingNode) {
      return draggingNode.level !== 1
    },
    scrollFixed() {
      const form = document.querySelector('.category-form')
      const top = form.getBoundingClientRect().top
      if (top < 0) {
        this.isFixedForm = true
      } else {
        this.isFixedForm = false
      }
    },
    treeOpen() {
      const nodeKey = this.$refs.tree.getCurrentKey()
      if (!nodeKey) {
        this.$message({
          message: '请先选中节点',
          type: 'warning'
        })
        return false
      }
      const node = this.$refs.tree.getNode(this.$refs.tree.getCurrentKey())
      if (!node.expanded) {
        document
          .querySelector('.is-current .el-tree-node__content>span')
          .click()
      }
    },
    treeClose() {
      const nodeKey = this.$refs.tree.getCurrentKey()
      if (!nodeKey) {
        this.$message({
          message: '请先选中节点',
          type: 'warning'
        })
        return false
      }
      const node = this.$refs.tree.getNode(this.$refs.tree.getCurrentKey())
      if (node.expanded) {
        document
          .querySelector('.is-current .el-tree-node__content>span')
          .click()
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.category-tree {
  ::v-deep .el-tree--highlight-current {
    .is-current {
      & > .el-tree-node__content {
        background-color: #dbedfe !important;
      }
    }
  }
}
.category-form {
  ::v-deep .is-disabled {
    .el-textarea__inner {
      color: #67686a !important;
    }
    .el-input__inner {
      color: #67686a !important;
    }
  }
  .category-body-form {
    &.form-fixed {
      position: fixed;
      top: 0;
      width: 700px;
    }
  }
}
.tree-btn-content {
  padding: 10px 0;
}
</style>
